<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>制定入库单</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script>

$(function () {
    $("#FormulateTab").bootstrapTable({
        method: "get",
        contentType: "application/json;charset=utf-8",
        url: "/sgather/findFormulateGather",
        striped: true,
        pageNumber: 1,
        pagination: true,
        sidePagination: 'server',
        pageSize: 5,
        pageList: [3, 5, 6, 10],
        queryParams: function (params) {
            return {
                // 计算页号(当前页)
                pageNumber: (params.offset / params.limit) + 1,
                // 计算页大小
                pageSize: params.limit,
            }
        },
        columns: [
            {title: '入库单编号', field: 'gatherId', align: 'center'},
            {title: '入库理由', field: 'reason', align: 'center', formatter: function (value, row, index) {
                    if (value == "r001-1") {
                        return "生产入库";
                    } else if (value == "r001-2") {
                        return "库存初始";
                    } else if (value == "r001-3") {
                        return "赠送";
                    } else if (value == "r001-4") {
                        return "内部归还"
                    } else {
                        return "其他归还";
                    }
                }
            },
            {title: '入库详细理由',field: 'reasonexact',align: 'center'},
            {title: '登记时间',field: 'registerTime',align: 'center'},
            {title: '总件数', field: 'amountSum', align: 'center'},
            {title: '总金额', field: 'costPriceSum', align: 'center'},
            {title: '入库调度',field: 'id',align: 'center',
                formatter: function (value, row, index) {
                    var btn1="<button  class='btn btn-primary btn-sm'  data-toggle='modal' data-target='#myModal2' onclick='FormulateGather("+JSON.stringify(row)+")'>入库调度</button>";
                    return btn1;
                }
            },
        ]
    })
})

        function FormulateGather(data) {
                console.log(data);
                $(".gatherId").val(data.gatherId);
            var re='';
            if (data.reason == "r001-1") {
                re= "生产入库";
            } else if (data.reason == "r001-2") {
                re= "库存初始";
            } else if (data.reason == "r001-3") {
                re= "赠送";
            } else if (data.reason == "r001-4") {
                re= "内部归还"
            } else {
                re= "其他归还";
            }
            $("#reason").val(re);
            $("#amountSum").val(data.amountSum);
            $("#costPriceSum").val(data.costPriceSum);
            $("#table2").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/sgather/findGatherDetailsById",
                queryParams: function (params) {
                    return {
                            id:data.id,
                    }
                },
                columns: [
                    {title: '序号', field: 'id', align: 'center'},
                    {title: '产品名称', field: 'productName', align: 'center'},
                    {title: '产品编号', field: 'productId', align: 'center'},
                    {title: '应入库件数', field: 'amount', align: 'center'},
                    {title: '已入库件数', field: 'gatheredAmount', align: 'center',formatter:function (value,row,index) {
                                    if(value==null){
                                        return 0;
                                    }
                        }},
                    {
                        title: '调度', field: 'gatherTag', align: 'center',
                        formatter: function (value, row, index) {

                            if(value=='k002-2'){
                                return "<span style='color: greenyellow'>完成</span>";
                            }else{
                                var btn1 = "<button  class='btn btn-primary btn-sm' onclick='scheduling("+JSON.stringify(row)+")' data-toggle='modal' data-target='#myModal'>调度</button>";
                                return btn1;
                            }


                        }
                    },
                ]
            })
        }

function findAcc() {
    $.ajax({
        type: 'post',
        url: '/SysUser/queryUser',
        success: function (result) {
            $("#attemper").val(result.loginId);
        }
    })
}
            function scheduling(data) {
                findAcc()
                $("#id").val(data.id);
                $("#productId").val(data.productId);
                $("#product_name").val(data.productName);
                $("#cost_price").val(data.costPrice);
                $("#register_time").val(new Date().toLocaleString());
                if(data.amount!=null){
                    $("#amountSum2").val(data.amount);
                }

                $("#costPriceSum2").val(data.subtotal);
                $.ajax({
                    type:'post',
                    url:'/sgather/queryCellByProductId',
                    data:'productid='+data.productId,
                    success:function (result) {
                            var a=result.firstKindId+"-"+result.secondKindId+"-"+result.thirdKindId;
                            var b=result.firstKindName+"-"+result.secondKindName+"-"+result.thirdKindName;
                            var c=result.maxCapacityAmount-result.amount;
                            console.log(c)
                        $("#tbody").html("");
                            $("#tbody").append("<tr>" +
                                " <td>"+result.id+"</td>" +
                                " <td>成品房</td>" +
                                " <td>"+a+"</td>" +
                                " <td>"+b+"</td>" +
                                " <td>"+c+"</td>" +
                                " <td>"+data.amount+"</td>" +
                                "</tr>")
                    }
                })



            }

            function SubmitDispatch() {
                    $.ajax({
                        type:'post',
                        url:'/sgather/UpdateGather_details',
                        data:'id='+$("#id").val(),
                        success:function (result) {
                            if(result==1){
                                alert("提交成功")
                                window.location.reload();
                            }
                        }
                    })
            }

    </script>
</head>
<body>
<table id="FormulateTab" class="table">

</table>

<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">入库调度单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                    <div>
                            <div class="form-inline row" style="margin-left: 5%">
                                <span class="">&nbsp;&nbsp;&nbsp;入库单编号：</span>
                                <input type="text" readonly id="gatherId" class="form-control col-3 gatherId">
                                <div class="col-2"></div>
                                <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;入库理由：</span>
                                <input id="reason" readonly class="form-control col-3">
                                </input>
                            </div>

                        </div>

                        <table id="table2" class="table tab-content table-hover" style="margin-top: 20px;border: 1px black solid">

                        </table>
                        <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">

                            <span class="">应入库总件数：</span>
                            <input type="text" readonly id="amountSum" class="form-control col-3">
                            <div class="col-2"></div>
                            <span class="">已入库总件数：</span>
                            <input type="text" value="0" readonly id="amount_Sum" class="form-control col-3">
                        </div>
                        <div class="form-inline row" style="margin-top: 20px ;margin-left: 5%">

                            <span class="">应入库总成本：</span>
                            <input type="text"   readonly id="costPriceSum" class="form-control col-3">
                            <div class="col-2"></div>
                            <span class="">已入库总成本：</span>
                            <input id="costPrice_Sum" value="0" readonly type="text" class="form-control col-3">
                        </div>

                </div>



            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
            </div>
        </div>
    </div>

<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">入库调度单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                        <input type="hidden" id="id">
                    <div class="form-inline row" style="margin-left: 5%">
                        <span class="">&nbsp;&nbsp;&nbsp;入库单编号：</span>
                        <input type="text" readonly id="gatherId2" class="form-control col-3 gatherId">
                        <div class="col-2"></div>
                        <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品编号：</span>
                        <input id="productId" readonly class="form-control col-3">
                    </div>

                <div class="form-inline row" style="margin-left: 5%;margin-top: 20px">
                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;产品名称：</span>
                    <input type="text" readonly id="product_name" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;成本单价：</span>
                    <input id="cost_price" readonly class="form-control col-3">
                </div>


                <table id="table3" class="table tab-content table-hover" style="margin-top: 20px;border: 1px black solid">
                    <thead>
                    <tr>
                        <td>序号</td>
                        <td>库房名称</td>
                        <td>存储地址编号</td>
                        <td>存储地址名称</td>
                        <td>当前可存数量</td>
                        <td>本次存放数量</td>
                    </tr>
                    </thead>
                    <tbody id="tbody">

                    </tbody>
                </table>
                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">

                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;调度人：</span>
                    <input type="text" readonly id="attemper" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;调度时间：</span>
                    <input type="text" value="0" readonly id="register_time" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">

                    <span class="">应入库总件数：</span>
                    <input type="text" readonly id="amountSum2" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已入库总件数：</span>
                    <input type="text" value="0" readonly id="amount_Sum2" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px ;margin-left: 5%">

                    <span class="">应入库总成本：</span>
                    <input type="text"   readonly id="costPriceSum2" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已入库总成本：</span>
                    <input id="costPrice_Sum2" value="0" readonly type="text" class="form-control col-3">
                </div>

            </div>



            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="SubmitDispatch()" data-dismiss="modal">提交</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>